home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / source / uEditContact.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-10-14  |  34.4 KB  |  1,167 lines

  1. unit uEditContact;
  2.  
  3. {
  4. *******************************************************************************
  5. * Descriptions: Main Unit for FMA
  6. * $Source: /cvsroot/fma/fma/uEditContact.pas,v $
  7. * $Locker:  $
  8. *
  9. * Todo:
  10. *    - add picture and sound support
  11. *
  12. * Change Log:
  13. * $Log: uEditContact.pas,v $
  14. * Revision 1.20.6.1  2004/10/14 16:43:24  z_stoichev
  15. * Bugfixes
  16. *
  17. * Revision 1.20  2004/07/06 20:13:58  lordlarry
  18. * Fixed Changing email address has no effect
  19. *
  20. * Revision 1.19  2004/07/06 14:06:52  z_stoichev
  21. * - Added Personalization default contact image.
  22. *
  23. * Revision 1.18  2004/07/01 14:41:30  z_stoichev
  24. * Outlook summary fille in.
  25. * Save notes renamed to export.
  26. *
  27. * Revision 1.17  2004/06/29 10:43:20  z_stoichev
  28. * Added Call notes support
  29. * More prefferences added
  30. *
  31. * Revision 1.16  2004/06/26 16:45:52  lordlarry
  32. * Implemented Unlinking of Synced contact
  33. *
  34. * Revision 1.15  2004/06/23 13:50:39  z_stoichev
  35. * Outlook updates
  36. *
  37. * Revision 1.14  2004/06/18 13:49:37  z_stoichev
  38. * - Added Edit Contact UI sanity feedback.
  39. * - Added Edit Contact DisplayName auto-update.
  40. *
  41. * Revision 1.13  2004/06/15 13:47:01  z_stoichev
  42. * Outlook DisplayName, FileAs, GUID support
  43. * Interface Bugfixes
  44. *
  45. * Revision 1.12  2004/05/21 14:39:47  z_stoichev
  46. * Fixed Contact name changes not saved
  47. * Added Contact Display name support
  48. *
  49. * Revision 1.11  2004/05/19 18:34:15  z_stoichev
  50. * Build 0.1.0.35c
  51. *
  52. * Revision 1.10  2004/04/01 15:07:47  z_stoichev
  53. * Apply button fixes
  54. *
  55. * Revision 1.9  2004/03/26 18:37:39  z_stoichev
  56. * Build 0.1.0.35 RC5
  57. *
  58. * Revision 1.8  2004/03/11 12:44:59  z_stoichev
  59. * Fixed Font Charset.
  60. *
  61. * Revision 1.7  2004/01/28 17:12:14  z_stoichev
  62. * Allow editing ME when no obex.
  63. *
  64. * Revision 1.6  2003/12/11 12:39:55  z_stoichev
  65. * Fixed upload and select issue.
  66. *
  67. * Revision 1.5  2003/12/02 16:39:16  z_stoichev
  68. * Fixed error when editing own card.
  69. *
  70. * Revision 1.4  2003/12/01 16:01:38  z_stoichev
  71. * Support for Own card editing.
  72. * Auto set picture on upload.
  73. *
  74. * Revision 1.3  2003/11/28 09:38:07  z_stoichev
  75. * Merged with branch-release-1-1 (Fma 0.10.28c)
  76. *
  77. * Revision 1.2.2.13  2003/11/26 12:25:01  z_stoichev
  78. * Allow 'p' char (pause)  into numbers.
  79. * Tab settings update on activate fixed.
  80. *
  81. * Revision 1.2.2.12  2003/11/21 13:24:15  z_stoichev
  82. * Fixed Show window caption, when names are empty.
  83. * Allow creating new contact with default cell number.
  84. *
  85. * Revision 1.2.2.11  2003/11/19 13:28:40  z_stoichev
  86. * Cell word changed to Mobile.
  87. *
  88. * Revision 1.2.2.10  2003/11/19 12:55:00  z_stoichev
  89. * Allow # and * in numbers.
  90. *
  91. * Revision 1.2.2.9  2003/11/11 18:12:23  z_stoichev
  92. * Contact personalization changes.
  93. *
  94. * Revision 1.2.2.8  2003/11/11 13:24:02  z_stoichev
  95. * Add personalization support.
  96. *
  97. * Revision 1.2.2.7  2003/11/10 14:03:09  z_stoichev
  98. * RC3
  99. *
  100. * Revision 1.2.2.6  2003/11/07 13:56:49  z_stoichev
  101. * Add support for editing SIM records.
  102. *
  103. * Revision 1.2.2.5  2003/11/07 11:16:54  z_stoichev
  104. * Fixed edit contact do not apply changes.
  105. *
  106. * Revision 1.2.2.4  2003/10/30 13:25:46  z_stoichev
  107. * Fixed phone numbers sanity check.
  108. * Added Beep on wrong char input.
  109. *
  110. * Revision 1.2.2.3  2003/10/28 12:46:56  z_stoichev
  111. * Add default number selection.
  112. * Dont update contact as modified if only
  113. * custom Fma data is modified.
  114. *
  115. * Revision 1.2.2.2  2003/10/27 15:23:56  z_stoichev
  116. * Clear cached information button is added.
  117. *
  118. * Revision 1.2.2.1  2003/10/27 07:22:54  z_stoichev
  119. * Build 0.1.0 RC1 Initial Checkin.
  120. *
  121. * Revision 1.2  2003/10/24 12:32:21  z_stoichev
  122. * Full name is updated on name, surname change.
  123. * Show some default picture and sound infos.
  124. * Fixed: Name + surname length + space = 30.
  125. *
  126. * Revision 1.1  2003/10/23 11:32:41  z_stoichev
  127. * Initial checkin.
  128. *
  129. *
  130. *
  131. }
  132.  
  133. interface
  134.  
  135. uses
  136.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  137.   Dialogs, ExtCtrls, StdCtrls, TntStdCtrls, ComCtrls, Buttons, uSyncPhonebook,
  138.   Menus, TntComCtrls, MPlayer, GR32_Image, uContactSync;
  139.  
  140. type
  141.   TfrmEditContact = class(TForm)
  142.     PageControl1: TPageControl;
  143.     TabSheet1: TTabSheet;
  144.     Image1: TImage;
  145.     Bevel1: TBevel;
  146.     Label1: TLabel;
  147.     txtTitle: TTntEdit;
  148.     txtName: TTntEdit;
  149.     Label2: TLabel;
  150.     Label4: TLabel;
  151.     txtOrganization: TTntEdit;
  152.     txtEmail: TTntEdit;
  153.     Label5: TLabel;
  154.     Bevel2: TBevel;
  155.     Label6: TLabel;
  156.     txtHome: TTntEdit;
  157.     Label7: TLabel;
  158.     txtWork: TTntEdit;
  159.     Label8: TLabel;
  160.     txtCell: TTntEdit;
  161.     Label9: TLabel;
  162.     txtFax: TTntEdit;
  163.     Label10: TLabel;
  164.     txtOther: TTntEdit;
  165.     TabSheet2: TTabSheet;
  166.     OkButton: TButton;
  167.     CancelButton: TButton;
  168.     ApplyButton: TButton;
  169.     GroupBox1: TGroupBox;
  170.     Panel1: TPanel;
  171.     btnPicSel: TButton;
  172.     Label12: TLabel;
  173.     Label13: TLabel;
  174.     lblPicDim: TLabel;
  175.     Label15: TLabel;
  176.     imgDim: TImage;
  177.     lblPicName: TLabel;
  178.     lblPicSize: TLabel;
  179.     btnPicNew: TButton;
  180.     GroupBox2: TGroupBox;
  181.     btnPicDel: TButton;
  182.     Label14: TLabel;
  183.     Label16: TLabel;
  184.     Label17: TLabel;
  185.     btnSndNew: TButton;
  186.     btnSndDel: TButton;
  187.     btnSndSel: TButton;
  188.     imgSnd: TImage;
  189.     lblSndType: TLabel;
  190.     lblSndName: TLabel;
  191.     lblSndSize: TLabel;
  192.     Label11: TLabel;
  193.     lblPicPal: TLabel;
  194.     TabSheet3: TTabSheet;
  195.     Label18: TLabel;
  196.     ResetButton: TButton;
  197.     Label19: TLabel;
  198.     TabSheet4: TTabSheet;
  199.     GroupBox3: TGroupBox;
  200.     cbDefaultNum: TComboBox;
  201.     Label20: TLabel;
  202.     Label21: TLabel;
  203.     Label22: TLabel;
  204.     Label23: TLabel;
  205.     PopupMenu1: TPopupMenu;
  206.     MediaPlayer1: TMediaPlayer;
  207.     SelImage: TImage32;
  208.     txtDisplayAs: TTntComboBox;
  209.     TabSheet5: TTabSheet;
  210.     GroupBox4: TGroupBox;
  211.     txtContactDataID: TTntEdit;
  212.     Label3: TLabel;
  213.     Button1: TButton;
  214.     Label26: TLabel;
  215.     GroupBox5: TGroupBox;
  216.     txtFileAs: TTntEdit;
  217.     Label25: TLabel;
  218.     Label27: TLabel;
  219.     Label24: TLabel;
  220.     Label28: TLabel;
  221.     TabSheet6: TTabSheet;
  222.     GroupBox6: TGroupBox;
  223.     CheckBox1: TCheckBox;
  224.     GroupBox7: TGroupBox;
  225.     MemoNotes: TTntMemo;
  226.     btNotesClear: TButton;
  227.     btNotesSave: TButton;
  228.     SaveDialog1: TSaveDialog;
  229.     GroupBox8: TGroupBox;
  230.     RadioButton1: TRadioButton;
  231.     RadioButton2: TRadioButton;
  232.     RadioButton3: TRadioButton;
  233.     Button2: TButton;
  234.     MemoDetails: TTntMemo;
  235.     procedure FormCreate(Sender: TObject);
  236.     procedure FormShow(Sender: TObject);
  237.     procedure txtChange(Sender: TObject);
  238.     procedure customChange(Sender: TObject);
  239.     procedure ApplyButtonClick(Sender: TObject);
  240.     procedure OkButtonClick(Sender: TObject);
  241.     procedure txtTelKeyPress(Sender: TObject; var Key: Char);
  242.     procedure ResetButtonClick(Sender: TObject);
  243.     procedure TabSheet4Show(Sender: TObject);
  244.     procedure txtPhoneChange(Sender: TObject);
  245.     procedure txtPhoneEnter(Sender: TObject);
  246.     procedure btnPicSelClick(Sender: TObject);
  247.     procedure btnSndSelClick(Sender: TObject);
  248.     procedure OnPicSelClick(Sender: TObject);
  249.     procedure OnSndSelClick(Sender: TObject);
  250.     procedure btnPicDelClick(Sender: TObject);
  251.     procedure btnSndDelClick(Sender: TObject);
  252.     procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  253.       var DoDefault: Boolean);
  254.     procedure PageControl1Change(Sender: TObject);
  255.     procedure btnUploadClick(Sender: TObject);
  256.     procedure txtChangeEditAs(Sender: TObject);
  257.     procedure OnChangeAsEnter(Sender: TObject);
  258.     procedure Button1Click(Sender: TObject);
  259.     procedure btNotesClearClick(Sender: TObject);
  260.     procedure MemoNotesChange(Sender: TObject);
  261.     procedure btNotesSaveClick(Sender: TObject);
  262.     procedure txtEmailChange(Sender: TObject);
  263.   private
  264.     { Private declarations }
  265.     FPhonePrev: string;
  266.     FPrevChangeAs: WideString;
  267.     FUseSIMMode,FLoadingData,FUseOwnMode: boolean;
  268.     FCustomImage: Boolean;
  269.     procedure DoSanityCheck;
  270.     procedure LoadContactData;
  271.     procedure SaveContactData;
  272.     procedure ShowFullName(Modified: WideString = '');
  273.     procedure FillDisplayNameList;
  274.     procedure UpdateDefNum(SetTo: integer = 0);
  275.     procedure UpdatePersonalize;
  276.     procedure Set_UseSIMMode(const Value: boolean);
  277.     procedure Set_UseOwnMode(const Value: boolean);
  278.     procedure SelectFile(Pos: TPoint; FileType: byte; Selected: WideString = '');
  279.     procedure SyncContactsError(Sender: TObject; const Message: String);
  280.     procedure SyncContactsConfirm(Sender: TObject; Contact: TContact;
  281.       Action: TContactAction; const Description: WideString;
  282.       var Confirmed: Boolean);
  283.     procedure Set_CustomImage(const Value: Boolean);
  284.   public
  285.     MaxFullNameLen: integer;
  286.     IsNew,Modified,customModified: boolean;
  287.     contact: TContactData;
  288.   published
  289.     procedure LoadAndMergeWith(AContact: TContactData);
  290.     property UseSIMMode: boolean read FUseSIMMode write Set_UseSIMMode default False;
  291.     property UseOwnMode: boolean read FUseOwnMode write Set_UseOwnMode default False;
  292.     property IsCustomImage: Boolean read FCustomImage write Set_CustomImage;
  293.   end;
  294.  
  295. var
  296.   frmEditContact: TfrmEditContact;
  297.  
  298. implementation
  299.  
  300. uses Unit1;
  301.  
  302. {$R *.dfm}
  303.  
  304. procedure TfrmEditContact.FormCreate(Sender: TObject);
  305. begin
  306.   lblPicDim.Left := imgDim.Left + imgDim.Width + 4;
  307.   lblPicName.Left := Label13.Left + Label13.Width + 4;
  308.   lblPicSize.Left := Label15.Left + Label15.Width + 4;
  309.   lblPicPal.Left := Label11.Left + Label11.Width + 4;
  310.   lblSndType.Left := imgSnd.Left + imgSnd.Width + 4;
  311.   lblSndName.Left := Label14.Left + Label14.Width + 4;
  312.   lblSndSize.Left := Label16.Left + Label16.Width + 4;
  313. {$IFNDEF VER150}
  314.   Form1.ThemeManager1.CollectForms(Self);
  315. {$ENDIF}
  316. end;
  317.  
  318. procedure TfrmEditContact.FormShow(Sender: TObject);
  319. begin
  320.   MaxFullNameLen := txtName.MaxLength;
  321.   LoadContactData;
  322.   PageControl1.ActivePageIndex := 0;
  323.   txtName.SetFocus;
  324. end;
  325.  
  326. procedure TfrmEditContact.LoadContactData;
  327. var
  328.   c: TColor;
  329.   b: boolean;
  330.   w: WideString;
  331.   procedure UpdateTelView(var Item: TTntEdit);
  332.   begin
  333.     { Always enable, and disable only empty Edits }
  334.     if b or (Item.Text = '') then begin
  335.       Item.Enabled := b;
  336.       Item.Color := c;
  337.     end;
  338.   end;
  339. begin
  340.   FLoadingData := True;
  341.   try
  342.     FPrevChangeAs := '';
  343.     FPhonePrev := '';
  344.     if FUseSIMMode then c := clBtnFace else c := clWindow;
  345.     b := not FUseSIMMode;
  346.     // contact
  347.     txtTitle.Text := contact.title;
  348.     w := contact.name;
  349.     if contact.surname <> '' then
  350.       w := w + ' ' + contact.surname; // do not use GetContactFullName here!
  351.     txtName.Text := w;
  352.     txtContactDataID.Text := GUIDToString(contact.CDID);
  353.     txtFileAs.Text := contact.displayname;
  354.     txtDisplayAs.Text := contact.displayname;
  355.     txtOrganization.Text := contact.org;
  356.     txtEmail.Text := contact.email;
  357.     txtHome.Text := contact.home;
  358.     txtWork.Text := contact.work;
  359.     txtCell.Text := contact.cell;
  360.     txtFax.Text := contact.fax;
  361.     txtOther.Text := contact.other;
  362.     ShowFullName;
  363.     FillDisplayNameList;
  364.     if not (FUseSIMMode or FUseOwnMode) then begin
  365.       // Personalize, will fill data on tabsheet open
  366.       btnPicDel.Click;
  367.       btnSndDel.Click;
  368.       // Preferences
  369.       UpdateDefNum(contact.DefaultIndex);
  370.     end;
  371.     { Leave only used field for editing, or enable all fields for new contacts }
  372.     if FUseSIMMode then begin
  373.       if (txtCell.Text <> '') or (txtHome.Text <> '') or (txtWork.Text <> '') or
  374.         (txtFax.Text <> '') or (txtOther.Text <> '') then begin
  375.         UpdateTelView(txtCell);
  376.         UpdateTelView(txtHome);
  377.         UpdateTelView(txtWork);
  378.         UpdateTelView(txtFax);
  379.         UpdateTelView(txtOther);
  380.       end
  381.       else if not Form1.frmSIMEdit.IsMEMode then begin
  382.         { For SIM card enable only cell phone }
  383.         UpdateTelView(txtHome);
  384.         UpdateTelView(txtWork);
  385.         UpdateTelView(txtFax);
  386.         UpdateTelView(txtOther);
  387.       end;
  388.     end
  389.     else begin
  390.       GetContactNotes(@contact,MemoNotes.Lines);
  391.       MemoNotesChange(nil);
  392.       GetContactDetails(@contact,MemoDetails.Lines);
  393.     end;
  394.   finally
  395.     FLoadingData := False;
  396.   end;
  397.   // done
  398.   ResetButton.Enabled := not IsNew;
  399.   ApplyButton.Enabled := False;
  400.   Modified := False;
  401.   customModified := False;
  402. end;
  403.  
  404. procedure TfrmEditContact.SaveContactData;
  405. var
  406.   i: integer;
  407.   s,a: WideString;
  408. begin
  409.   contact.title := txtTitle.text;
  410.   contact.org := txtOrganization.text;
  411.   { Update contact name and surname }
  412.   a := GetContactFullName(@contact);
  413.   s := Trim(txtName.text);
  414.   i := Pos(' ',s);
  415.   if i = 0 then begin
  416.     contact.name := s;
  417.     contact.surname := '';
  418.   end
  419.   else begin
  420.     contact.name := Copy(s,1,i-1);
  421.     Delete(s,1,i);
  422.     contact.surname := Trim(s);
  423.   end;
  424.   (* Commented out since will keep DisplayName as fma internal setting
  425.   s := GetContactFullName(@contact);
  426.   if WideCompareText(a,s) <> 0 then
  427.     { If name/surname are changed, reset display name, since SE T610
  428.       doesnt support displayname vCard peoperty }
  429.     txtDisplayAs.Text := s;
  430.   *)
  431.   contact.displayname := txtDisplayAs.Text;
  432.   contact.email := txtEmail.text;
  433.   contact.home := txtHome.text;
  434.   contact.work := txtWork.text;
  435.   contact.cell := txtCell.text;
  436.   contact.fax := txtFax.text;
  437.   contact.other := txtOther.text;
  438.   if not (FUseSIMMode or FUseOwnMode) then begin
  439.     contact.DefaultIndex := cbDefaultNum.ItemIndex;
  440.     contact.picture := lblPicName.Caption;
  441.     contact.sound := lblSndName.Caption;
  442.     contact.CDID := StringToGUID(txtContactDataID.Text);
  443.   end;
  444.   SetContactNotes(@contact,MemoNotes.Lines);
  445.   { Dont change modified flags here, since we'll use them in SyncPhonebook.
  446.     Only disable apply button. }
  447.   ApplyButton.Enabled := False;
  448. end;
  449.  
  450. procedure TfrmEditContact.txtChange(Sender: TObject);
  451. begin
  452.   ApplyButton.Enabled := not IsNew;
  453.   customModified := True;
  454. end;
  455.  
  456. procedure TfrmEditContact.ApplyButtonClick(Sender: TObject);
  457. begin
  458.   DoSanityCheck;
  459.   SaveContactData;
  460. end;
  461.  
  462. procedure TfrmEditContact.OkButtonClick(Sender: TObject);
  463. begin
  464.   DoSanityCheck;
  465.   if ApplyButton.Enabled or IsNew then
  466.     SaveContactData;
  467.   ModalResult := mrOk;  
  468. end;
  469.  
  470. procedure TfrmEditContact.txtTelKeyPress(Sender: TObject; var Key: Char);
  471. begin
  472.   case ord(Key) of
  473.     8, 48..57: ;
  474.     35, 42: ; // # and * (for special service numbers)
  475.     3, 22, 24, 26: ; //escape CTRL+C,V,X,Z ;)
  476.     43: with (Sender as TTntEdit) do begin
  477.       if (Pos('+',Text) <> 0) or (SelStart <> 0) then begin
  478.         Key := #0;     //only the first char can be '+'
  479.         Beep;
  480.       end;
  481.     end;
  482.     112: ; // p (pause)
  483.     else begin
  484.       Key := #0;
  485.       Beep;
  486.     end;
  487.   end;
  488. end;
  489.  
  490. procedure TfrmEditContact.ResetButtonClick(Sender: TObject);
  491. begin
  492.   FillChar(contact.Position,SizeOf(contact.Position),0);
  493.   ApplyButton.Enabled := not IsNew;
  494.   customModified := True;
  495. end;
  496.  
  497. procedure TfrmEditContact.TabSheet4Show(Sender: TObject);
  498. begin
  499.   UpdateDefNum;
  500. end;
  501.  
  502. procedure TfrmEditContact.UpdateDefNum(SetTo: integer);
  503. var
  504.   selpos: integer;
  505. begin
  506.   if SetTo = 0 then selpos := cbDefaultNum.ItemIndex else selpos := SetTo;
  507.   cbDefaultNum.Items.Clear;
  508.   // see TContactData.DefaultIndex
  509.   // 0 none;1 cell;2 work;3 home;4 other
  510.   cbDefaultNum.Items.Add('None');
  511.   if txtCell.Text <> '' then cbDefaultNum.Items.Add('Mobile ['+txtCell.Text+']');
  512.   if txtWork.Text <> '' then cbDefaultNum.Items.Add('Work ['+txtWork.Text+']');
  513.   if txtHome.Text <> '' then cbDefaultNum.Items.Add('Home ['+txtHome.Text+']');
  514.   if txtOther.Text <> '' then cbDefaultNum.Items.Add('Other ['+txtOther.Text+']');
  515.   if (selpos < 0) or (selpos >= cbDefaultNum.Items.Count) then
  516.     selpos := 0; // Out of range goes to None
  517.   cbDefaultNum.ItemIndex := selpos;
  518. end;
  519.  
  520. procedure TfrmEditContact.customChange(Sender: TObject);
  521. begin
  522.   ApplyButton.Enabled := not IsNew;
  523.   customModified := True;
  524. end;
  525.  
  526. procedure TfrmEditContact.txtPhoneChange(Sender: TObject);
  527. const
  528.   sem: boolean = False;
  529. var
  530.   i: integer;
  531.   s: string;
  532.   b: boolean;
  533. begin
  534.   if {not FLoadingData and} not sem then
  535.     try
  536.       sem := true;
  537.       with (Sender as TTntEdit) do begin
  538.         b := False;
  539.         s := Text;
  540.         i := 1;
  541.         while i <= Length(s) do begin
  542.           if ((i > 1) and (s[1] = '+') and (s[i] = '+')) or
  543.             (Pos('+',s) > 1) or not (s[i] in ['+','0'..'9','#','*','p']) then begin
  544.               Delete(s,i,1);
  545.               b := True;
  546.             end
  547.           else
  548.             inc(i);
  549.         end;
  550.         if s <> Text then Text := s;
  551.         if s <> FPhonePrev then begin
  552.           FPhonePrev := s;
  553.           ApplyButton.Enabled := not IsNew;
  554.           Self.Modified := True;
  555.         end;
  556.         if b then Beep;
  557.       end;
  558.     finally
  559.       sem := False;
  560.     end;
  561. end;
  562.  
  563. procedure TfrmEditContact.txtPhoneEnter(Sender: TObject);
  564. begin
  565.   FPhonePrev := (Sender as TTntEdit).Text;
  566. end;
  567.  
  568. procedure TfrmEditContact.Set_UseSIMMode(const Value: boolean);
  569. var
  570.   i: integer;
  571.   c: TColor;
  572.   b: boolean;
  573. begin
  574.   FUseSIMMode := Value;
  575.   if Value then c := clBtnFace else c := clWindow;
  576.   b := not Value;
  577.   txtTitle.Enabled := b;
  578.   txtTitle.Color := c;
  579.   txtOrganization.Enabled := b;
  580.   txtOrganization.Color := c;
  581.   txtEmail.Enabled := b;
  582.   txtEmail.Color := c;
  583.   txtDisplayAs.Enabled := b;
  584.   txtDisplayAs.Color := c;
  585.   { In SIM mode leave only General tab visible }
  586.   for i := 1 to PageControl1.PageCount-1 do
  587.     PageControl1.Pages[i].TabVisible := b;
  588. end;
  589.  
  590. procedure TfrmEditContact.SelectFile(Pos: TPoint; FileType: byte; Selected: WideString);
  591. var
  592.   m: TMenuItem;
  593.   Node,Item: TTntTreeNode;
  594.   Offline: boolean;
  595.   What: string;
  596.   ImgIdx: integer;
  597.   rec: TSearchRec;
  598. begin
  599.   Offline := not Form1.FConnected or not Form1.FUseObex;
  600.   PopupMenu1.Items.Clear;
  601.   if Offline then begin
  602.     case FileType of
  603.       0: What := '\pic\*.*';
  604.       1: What := '\snd\*.*';
  605.     end;
  606.     if FindFirst(ExePath+'data\'+Form1.PhoneIdentity+What,faAnyFile,rec) = 0 then
  607.     try
  608.       repeat
  609.         ImgIdx := Form1.ExplorerFindExtImage(ExtractFileExt(rec.Name));
  610.         if ImgIdx = -1 then continue;
  611.         m := TMenuItem.Create(nil);
  612.         try
  613.           m.AutoHotkeys := maManual;
  614.           m.Caption := rec.Name;
  615.           m.Tag := rec.Size;
  616.           m.Hint := rec.Name; // ignored in offline mode
  617.           m.ImageIndex := ImgIdx;
  618.           case FileType of
  619.             0: m.OnClick := OnPicSelClick;
  620.             1: m.OnClick := OnSndSelClick;
  621.           end;
  622.           if Selected <> '' then begin
  623.             if WideCompareText(rec.Name,Selected) = 0 then begin
  624.               m.Click;
  625.               m.Free;
  626.               break;
  627.             end;
  628.             m.Free;
  629.           end
  630.           else
  631.             PopupMenu1.Items.Add(m);
  632.         except
  633.           m.Free;
  634.         end;
  635.       until FindNext(rec) <> 0;
  636.     finally
  637.       FindClose(rec);
  638.     end;
  639.   end
  640.   else begin
  641.     Node := Form1.FindObexFolderNode(FileType);
  642.     if Assigned(Node) then begin
  643.       Item := Node.getFirstChild;
  644.       while Item <> nil do
  645.       try
  646.         m := TMenuItem.Create(nil);
  647.         try
  648.           m.AutoHotkeys := maManual;
  649.           m.Caption := Item.Text;
  650.           m.Tag := Item.StateIndex;
  651.           m.Hint := Node.Text + '/' + Item.Text;
  652.           m.ImageIndex := Item.ImageIndex;
  653.           case FileType of
  654.             0: m.OnClick := OnPicSelClick;
  655.             1: m.OnClick := OnSndSelClick;
  656.           end;
  657.           if Selected <> '' then begin
  658.             if WideCompareText(Item.Text,Selected) = 0 then begin
  659.               m.Click;
  660.               m.Free;
  661.               break;
  662.             end;
  663.             m.Free;
  664.           end
  665.           else
  666.             PopupMenu1.Items.Add(m);
  667.         except
  668.           m.Free;
  669.         end;
  670.       finally
  671.         Item := Node.GetNextChild(Item);
  672.       end;
  673.     end;
  674.   end;  
  675.   if PopupMenu1.Items.Count = 0 then begin
  676.     MessageBeep(MB_ICONASTERISK);
  677.     MessageDlg('You should refresh Explorer Files folder prior using this feature.'#13#13+
  678.       'Note that this is currently not supported if you are using IR connection.',mtInformation,[mbOk],0);
  679.   end
  680.   else
  681.     PopupMenu1.Popup(pos.X,pos.Y);
  682. end;
  683.  
  684. procedure TfrmEditContact.btnPicSelClick(Sender: TObject);
  685. var
  686.   p: TPoint;
  687. begin
  688.   p := btnPicSel.ClientToScreen(Point(0,btnPicSel.Height));
  689.   SelectFile(p,0);
  690. end;
  691.  
  692. procedure TfrmEditContact.btnSndSelClick(Sender: TObject);
  693. var
  694.   p: TPoint;
  695. begin
  696.   p := btnSndSel.ClientToScreen(Point(0,btnSndSel.Height));
  697.   SelectFile(p,1);
  698. end;
  699.  
  700. procedure TfrmEditContact.OnPicSelClick(Sender: TObject);
  701. var
  702.   Filename,Fullpath,Objectname: WideString;
  703.   Filesize: integer;
  704. begin
  705.   btnPicSel.Enabled := False;
  706.   btnSndSel.Enabled := False;
  707.   try
  708.     Objectname := (Sender as TMenuItem).Hint;
  709.     Filename := (Sender as TMenuItem).Caption;
  710.     Filesize := (Sender as TMenuItem).Tag;
  711.     Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\pic\';
  712.  
  713.     lblPicDim.Caption := '';
  714.     lblPicSize.Caption := '';
  715.     lblPicPal.Caption := '';
  716.     lblPicName.Caption := '(Loading '+Filename+'...)';
  717.  
  718.     try
  719.       ForceDirectories(Fullpath);
  720.       if Form1.FConnected and Form1.FUseObex and not FileExists(Fullpath+Filename) then
  721.         Form1.ObexGetFile(Fullpath+Filename,Objectname,False);
  722.  
  723.       SelImage.Bitmap.LoadFromFile(Fullpath+Filename);
  724.       IsCustomImage := True;
  725.       btnPicDel.Enabled := True;
  726.     except
  727.       btnPicDel.Click;
  728.       raise;
  729.     end;
  730.  
  731.     lblPicName.Caption := Filename;
  732.     lblPicDim.Caption := Format('%dx%d (%dx%d pixels)',[SelImage.Width,SelImage.Height,
  733.       SelImage.Bitmap.BitmapInfo.bmiHeader.biWidth,-SelImage.Bitmap.BitmapInfo.bmiHeader.biHeight]);
  734.     lblPicSize.Caption := Format('%.1n KB (%d bytes)',[Filesize / 1024,Filesize]);
  735.     case SelImage.Bitmap.BitmapInfo.bmiHeader.biBitCount of
  736.        8: lblPicPal.Caption := 'Low-Color (256 colors)';
  737.       16: lblPicPal.Caption := 'Hi-Color (65535 colors)';
  738.       24: lblPicPal.Caption := 'True-Color (24-bit colors)';
  739.       32: lblPicPal.Caption := 'True-Color (32-bit colors)';
  740.       else lblPicPal.Caption := 'Low-Color (<256 colors)';
  741.     end;
  742.     ApplyButton.Enabled := not IsNew;
  743.     customModified := True;
  744.   finally
  745.     btnPicSel.Enabled := True;
  746.     btnSndSel.Enabled := True;
  747.   end;
  748. end;
  749.  
  750. procedure TfrmEditContact.OnSndSelClick(Sender: TObject);
  751. var
  752.   Filename,Fullpath,Objectname: WideString;
  753.   Filesize: integer;
  754. begin
  755.   btnPicSel.Enabled := False;
  756.   btnSndSel.Enabled := False;
  757.   try
  758.     Objectname := (Sender as TMenuItem).Hint;
  759.     Filename := (Sender as TMenuItem).Caption;
  760.     Filesize := (Sender as TMenuItem).Tag;
  761.     Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\snd\';
  762.  
  763.     lblSndType.Caption := '';
  764.     lblSndSize.Caption := '';
  765.     lblSndName.Caption := '(Loading '+Filename+'...)';
  766.  
  767.     try
  768.       ForceDirectories(Fullpath);
  769.       if Form1.FConnected and Form1.FUseObex and not FileExists(Fullpath+Filename) then
  770.         Form1.ObexGetFile(Fullpath+Filename,Objectname,False);
  771.  
  772.       MediaPlayer1.FileName := Fullpath+Filename;
  773.       MediaPlayer1.Enabled := True;
  774.     except
  775.       btnSndDel.Click;
  776.       raise;
  777.     end;
  778.  
  779.     lblSndName.Caption := Filename;
  780.     lblSndSize.Caption := Format('%.1n KB (%d bytes)',[Filesize / 1024,Filesize]);
  781.     try
  782.       MediaPlayer1.Open;
  783.       lblSndType.Caption := Format('Track length is %d samples (Custom format)',[MediaPlayer1.TrackLength[1]]);
  784.       btnSndDel.Enabled := True;
  785.     except
  786.       lblSndType.Caption := 'Unknown (Unsupported format)';
  787.       MediaPlayer1.Enabled := False;
  788.     end;
  789.     ApplyButton.Enabled := not IsNew;
  790.     customModified := True;
  791.   finally
  792.     btnPicSel.Enabled := True;
  793.     btnSndSel.Enabled := True;
  794.   end;
  795. end;
  796.  
  797. procedure TfrmEditContact.btnPicDelClick(Sender: TObject);
  798. begin
  799.   if lblPicName.Caption <> '' then begin
  800.     ApplyButton.Enabled := not IsNew;
  801.     customModified := True;
  802.   end;  
  803.   lblPicDim.Caption := '128x127 (0x0 pixels)';
  804.   lblPicName.Caption := '';
  805.   lblPicSize.Caption := '0,0 KB (0 bytes)';
  806.   lblPicPal.Caption := 'Hi-Color (65535 colors)';
  807.   SelImage.Bitmap.Clear;
  808.   IsCustomImage := False;
  809.   btnPicDel.Enabled := False;
  810. end;
  811.  
  812. procedure TfrmEditContact.btnSndDelClick(Sender: TObject);
  813. begin
  814.   if lblSndName.Caption <> '' then begin
  815.     ApplyButton.Enabled := not IsNew;
  816.     customModified := True;
  817.   end;  
  818.   lblSndType.Caption := '(polyphonic stereo sound, supported by phone)';
  819.   lblSndName.Caption := '';
  820.   lblSndSize.Caption := '0,0 KB (0 bytes)';
  821.   MediaPlayer1.Close;
  822.   MediaPlayer1.Enabled := False;
  823.   btnSndDel.Enabled := False;
  824. end;
  825.  
  826. procedure TfrmEditContact.UpdatePersonalize;
  827. var
  828.   m: TMenuItem;
  829.   f: TFileStream;
  830.   amod,cmod,OldApply: boolean;
  831.   procedure LoadFile(fname: string; ftype: byte);
  832.   var
  833.     dir: string;
  834.   begin
  835.     { Emulate popup menu click here in order to select default
  836.       contact picture/sound file. }
  837.     case ftype of
  838.       0: dir := '\pic\';
  839.       1: dir := '\snd\';
  840.     end;
  841.     m := TMenuItem.Create(nil);
  842.     try
  843.       m.Caption := fname;
  844.       try
  845.         f := TFileStream.Create(ExePath+'data\'+Form1.PhoneIdentity+dir+fname,fmOpenRead);
  846.         try
  847.           m.Tag := f.Size;
  848.         finally
  849.           f.Free;
  850.         end;
  851.       except
  852.         m.Tag := 0;
  853.       end;
  854.       case ftype of
  855.         0: OnPicSelClick(m);
  856.         1: OnSndSelClick(m);
  857.       end;
  858.     finally
  859.       m.Free;
  860.     end;
  861.   end;
  862. begin
  863.   OldApply := ApplyButton.Enabled;
  864.   { Show window while updateing }
  865.   TabSheet2.Update;
  866.   amod := Modified;
  867.   cmod := customModified;
  868.   { Load personalization files on tabsheet enter }
  869.   if (lblPicName.Caption = '') and (contact.picture <> '') then
  870.     LoadFile(contact.picture,0);
  871.   if (lblSndName.Caption = '') and (contact.sound <> '') then
  872.     LoadFile(contact.sound,1);
  873.   Modified := amod;
  874.   customModified := cmod;
  875.   ApplyButton.Enabled := OldApply;
  876. end;
  877.  
  878. procedure TfrmEditContact.MediaPlayer1Click(Sender: TObject;
  879.   Button: TMPBtnType; var DoDefault: Boolean);
  880. begin
  881.   if Button = btStop then MediaPlayer1.Rewind;
  882. end;
  883.  
  884. procedure TfrmEditContact.PageControl1Change(Sender: TObject);
  885. begin
  886.   case PageControl1.ActivePageIndex of
  887.     1: UpdatePersonalize;
  888.     2: UpdateDefNum;
  889.   end;
  890. end;
  891.  
  892. procedure TfrmEditContact.Set_UseOwnMode(const Value: boolean);
  893. var
  894.   i: integer;
  895. begin
  896.   FUseOwnMode := Value;
  897.   { In Edit Own Card mode leave only General tab visible }
  898.   for i := 1 to PageControl1.PageCount-1 do
  899.     PageControl1.Pages[i].TabVisible := not FUseOwnMode;
  900. end;
  901.  
  902. procedure TfrmEditContact.btnUploadClick(Sender: TObject);
  903. var
  904.   m: TMenuItem;
  905.   ObjType: integer;
  906. begin
  907.   btnPicNew.Enabled := False;
  908.   btnSndNew.Enabled := False;
  909.   try
  910.     ObjType := TButton(Sender).Tag;
  911.     Form1.RequestConnection;
  912.     Form1.ActionToolsUpload.Execute;
  913.     m := TMenuItem.Create(nil);
  914.     try
  915.       m.AutoHotkeys := maManual;
  916.       m.Caption := ExtractFileName(Form1.OpenDialog1.FileName);
  917.       m.Hint := Form1.FindObexFolderName(ObjType)+'/'+m.Caption;
  918.       if ObjType = 0 then m.OnClick := OnPicSelClick
  919.         else m.OnClick := OnSndSelClick;
  920.       m.Click;
  921.     finally
  922.       m.Free;
  923.     end;
  924.   finally
  925.     btnPicNew.Enabled := True;
  926.     btnSndNew.Enabled := True;
  927.   end;
  928. end;
  929.  
  930. procedure TfrmEditContact.DoSanityCheck;
  931. var
  932.   TelCnt: integer;
  933. begin
  934.   { check name }
  935.   if Trim(txtName.Text) = '' then
  936.     raise EConvertError.Create('You have to enter contact name');
  937.   if Pos('"',txtName.Text) <> 0 then begin
  938.     if FUseSIMMode then
  939.       raise EConvertError.Create('Quotes are not allowed in SIM contact name');
  940.   end;
  941.   if Trim(txtDisplayAs.Text) = '' then
  942.     txtDisplayAs.Text := txtName.Text;
  943.   { check numbers }
  944.   TelCnt := 0;
  945.   if txtCell.Text <> ''  then inc(TelCnt);
  946.   if txtHome.Text <> ''  then inc(TelCnt);
  947.   if txtWork.Text <> ''  then inc(TelCnt);
  948.   if txtFax.Text <> ''   then inc(TelCnt);
  949.   if txtOther.Text <> '' then inc(TelCnt);
  950.   if TelCnt = 0 then
  951.     raise EConvertError.Create('You have to enter contact phone number');
  952.   if FUseSIMMode and (TelCnt > 1) then
  953.     raise EConvertError.Create('You have to enter only one phone number');
  954. end;
  955.  
  956. procedure TfrmEditContact.FillDisplayNameList;
  957. var
  958.   w,s: WideString;
  959.   i: integer;
  960. begin
  961.   txtDisplayAs.Items.Clear;
  962.   if txtName.Text <> '' then begin
  963.     { Move surname in front }
  964.     w := txtName.Text;
  965.     i := Length(w);
  966.     while (i >= 1) and (w[i] <> ' ') do dec(i);
  967.     s := Copy(w,1,i-1);
  968.     w := Copy(w,i+1,Length(w));
  969.     if s <> '' then w := w + ', ' + Trim(s);
  970.     { Fill list }
  971.     txtDisplayAs.Items.Add(txtName.Text);
  972.     if txtOrganization.Text <> '' then
  973.       txtDisplayAs.Items.Add(txtName.Text + ' ' + txtOrganization.Text);
  974.     if WideCompareText(w,txtName.Text) <> 0 then begin
  975.       txtDisplayAs.Items.Add(w);
  976.       if txtOrganization.Text <> '' then
  977.         txtDisplayAs.Items.Add(w + ' ' + txtOrganization.Text);
  978.     end;
  979.     if txtTitle.Text <> '' then begin
  980.       txtDisplayAs.Items.Add(txtTitle.Text + ' ' + txtName.Text);
  981.       if txtOrganization.Text <> '' then
  982.         txtDisplayAs.Items.Add(txtTitle.Text + ' ' + txtName.Text + ' ' + txtOrganization.Text);
  983.       if WideCompareText(w,txtName.Text) <> 0 then begin
  984.         txtDisplayAs.Items.Add(txtTitle.Text + ' ' + w);
  985.         if txtOrganization.Text <> '' then
  986.           txtDisplayAs.Items.Add(txtTitle.Text + ' ' + w + ' ' + txtOrganization.Text);
  987.       end;
  988.     end;
  989.   end;
  990. end;
  991.  
  992. procedure TfrmEditContact.ShowFullName(Modified: WideString);
  993. var
  994.   s,w: WideString;
  995.   i,j: integer;
  996. begin
  997.   s := Trim(txtName.Text);
  998.   if txtDisplayAs.Text = '' then
  999.     txtDisplayAs.Text := s;
  1000.   { Update DisplayAs default patterns }
  1001.   w := txtDisplayAs.Text;
  1002.   i := txtDisplayAs.Items.IndexOf(w);
  1003.   { Remove any emptied field }
  1004.   if (FPrevChangeAs <> '') and (Modified = '') then begin
  1005.     j := Pos(' '+FPrevChangeAs,w);
  1006.     if j = 0 then
  1007.       j := Pos(FPrevChangeAs+' ',w);
  1008.     if j <> 0 then
  1009.       Delete(w,j,Length(FPrevChangeAs)+1);
  1010.   end;
  1011.   { Update predefined values }
  1012.   FillDisplayNameList;
  1013.   if i <> -1 then begin
  1014.     { Predefined value was used, so update it with new fields }
  1015.     j := txtDisplayAs.Items.IndexOf(w);
  1016.     if j <> -1 then
  1017.       { unused field has been changed or field is emptied }
  1018.       i := j;
  1019.     { do not remove next sanity check, its used when an used field is changed }
  1020.     if (i >= 0) and (i < txtDisplayAs.Items.Count) then
  1021.       { Set to new predefined value }
  1022.       txtDisplayAs.ItemIndex := i; 
  1023.   end;
  1024.   { Udate dialog caption }
  1025.   if s <> '' then
  1026.     if FUseOwnMode then
  1027.       Caption := 'Own Business Card - '+s
  1028.     else
  1029.       Caption := 'Contact - '+s
  1030.   else
  1031.     Caption := 'Contact';
  1032. end;
  1033.  
  1034. procedure TfrmEditContact.txtChangeEditAs(Sender: TObject);
  1035. var
  1036.   w: WideString;
  1037. begin
  1038.   if not FLoadingData then begin
  1039.     w := (Sender as TTntEdit).Text;
  1040.     ShowFullName(w);
  1041.     FPrevChangeAs := w;
  1042.   end;
  1043.   ApplyButton.Enabled := not IsNew;
  1044.   Modified := True;
  1045. end;
  1046.  
  1047. procedure TfrmEditContact.OnChangeAsEnter(Sender: TObject);
  1048. begin
  1049.   FPrevChangeAs := (Sender as TTntEdit).Text;
  1050. end;
  1051.  
  1052. procedure TfrmEditContact.LoadAndMergeWith(AContact: TContactData);
  1053. var
  1054.   w: WideString;
  1055. begin
  1056.   LoadContactData;
  1057.   txtTitle.Text := AContact.title;
  1058.   w := AContact.name;
  1059.   if AContact.surname <> '' then
  1060.     w := w + ' ' + AContact.surname; // do not use GetContactFullName here!
  1061.   txtName.Text := w;
  1062.   txtFileAs.Text := AContact.displayname;
  1063.   txtOrganization.Text := AContact.org;
  1064.   txtEmail.Text := AContact.email;
  1065.   txtHome.Text := AContact.home;
  1066.   txtWork.Text := AContact.work;
  1067.   txtCell.Text := AContact.cell;
  1068.   txtFax.Text := AContact.fax;
  1069.   txtOther.Text := AContact.other;
  1070.   // - Do not copy displayname, it will be merged
  1071.   // txtDisplayAs.Text := AContact.displayname;
  1072.   // - Keep old GUID!
  1073.   // txtContactDataID.Text := GUIDToString(contact.CDID);
  1074.   // - Do not copy personalization!
  1075.   // cbDefaultNum.ItemIndex := AContact.DefaultIndex;
  1076.   // lblPicName.Caption := AContact.picture;
  1077.   // lblSndName.Caption := AContact.sound;
  1078. end;
  1079.  
  1080. procedure TfrmEditContact.Button1Click(Sender: TObject);
  1081. var SynchronizeContacts: TSynchronizeContacts;
  1082.     Fullpath: String;
  1083.     ID: String;
  1084. begin
  1085.   try
  1086.     ID := Form1.PhoneIdentity;
  1087.     Fullpath := ExePath;
  1088.     if ID <> '' then
  1089.       Fullpath := ExePath+'data\'+ID+'\dat\';
  1090.  
  1091.     SynchronizeContacts := TSynchronizeContacts.Create;
  1092.     try
  1093.       SynchronizeContacts.FileName := Fullpath + 'ContactSync.xml';
  1094.  
  1095.       SynchronizeContacts.OnError := SyncContactsError;
  1096.       SynchronizeContacts.OnConfirm := SyncContactsConfirm;
  1097.  
  1098.       SynchronizeContacts.Unlink(Contact.CDID);
  1099.     finally
  1100.       SynchronizeContacts.Free;
  1101.     end;
  1102.   except
  1103.     on E: Exception do begin
  1104.       SyncLogFmt('Error: Unlink aborted (%s: %s)', [E.ClassName, E.Message]);
  1105.       Form1.Status(Format('Error: Unlink aborted (%s: %s)', [E.ClassName, E.Message]));
  1106.       MessageDlg(Format('Error: Unlink aborted (%s: %s)', [E.ClassName, E.Message]), mtError, [mbOk], 0);
  1107.     end;
  1108.   end;
  1109. end;
  1110.  
  1111. procedure TfrmEditContact.SyncContactsError(Sender: TObject; const Message: String);
  1112. begin
  1113.   SyncLogFmt('Error: Unlink aborted (%s)', [Message]);
  1114.   Form1.Status(Format('Error: Unlink aborted (%s)', [Message]));
  1115.   MessageDlg(Format('Error: Unlink aborted (%s)', [Message]), mtError, [mbOk], 0);
  1116. end;
  1117.  
  1118. resourcestring
  1119.   SSyncContactsConfirm = '%s.' +
  1120.                          #13#10 + #13#10 +
  1121.                          'Is this ok?';
  1122.  
  1123. procedure TfrmEditContact.SyncContactsConfirm(Sender: TObject; Contact: TContact;
  1124.     Action: TContactAction; const Description: WideString; var Confirmed:
  1125.     Boolean);
  1126. begin
  1127.   Confirmed := MessageDlg(WideFormat(SSyncContactsConfirm, [Description]), mtConfirmation, [mbNo, mbYes], 0) = mrYes;
  1128. end;
  1129.  
  1130. procedure TfrmEditContact.btNotesClearClick(Sender: TObject);
  1131. begin
  1132.   MemoNotes.Clear;
  1133.   MemoNotesChange(nil);
  1134. end;
  1135.  
  1136. procedure TfrmEditContact.MemoNotesChange(Sender: TObject);
  1137. begin
  1138.   btNotesSave.Enabled := Trim(MemoNotes.Text) <> '';
  1139.   btNotesClear.Enabled := btNotesSave.Enabled;
  1140.   { SaveSettings will store changes in database, so we dont need
  1141.     to set modified flags here }
  1142.   ApplyButton.Enabled := True;
  1143. end;
  1144.  
  1145. procedure TfrmEditContact.btNotesSaveClick(Sender: TObject);
  1146. begin
  1147.   if SaveDialog1.FileName = '' then
  1148.     SaveDialog1.FileName := txtName.Text + '.txt';
  1149.   if SaveDialog1.Execute then
  1150.     MemoNotes.Lines.SaveToFile(SaveDialog1.FileName);
  1151. end;
  1152.  
  1153. procedure TfrmEditContact.Set_CustomImage(const Value: Boolean);
  1154. begin
  1155.   FCustomImage := Value;
  1156.   if not Value then
  1157.     SelImage.Bitmap.Assign(Form1.CommonBitmaps.Bitmap[0]);
  1158. end;
  1159.  
  1160. procedure TfrmEditContact.txtEmailChange(Sender: TObject);
  1161. begin
  1162.   ApplyButton.Enabled := not IsNew;
  1163.   Modified := True;
  1164. end;
  1165.  
  1166. end.
  1167.